home *** CD-ROM | disk | FTP | other *** search
/ Champak 132 (Alt) / Vol 132.iso / games / pupworld.swf / scripts / __Packages / Heroes / Follower.as < prev    next >
Encoding:
Text File  |  2011-06-09  |  7.5 KB  |  232 lines

  1. class Heroes.Follower extends Heroes.WorldObject
  2. {
  3.    var speechTimer;
  4.    var walkDistance;
  5.    var maxDistance;
  6.    var x;
  7.    var z;
  8.    var graphics;
  9.    var facing;
  10.    var state = "stand";
  11.    var slowSoundCount = 0;
  12.    var fastSoundCount = 0;
  13.    var maxSpeed = 9;
  14.    var facingDirection = 1;
  15.    function Follower()
  16.    {
  17.       super();
  18.       this._visible = true;
  19.       this.speechTimer = 4.9e-324;
  20.       this.walkDistance = 60;
  21.       this.maxDistance = 150;
  22.       this.playSound("walkies");
  23.    }
  24.    function onEnterFrame()
  25.    {
  26.       this.maxSpeed = this._parent.player.getRunningSpeed() - 2;
  27.       var _loc7_ = 10;
  28.       var _loc10_ = this._parent.player.x - this.x;
  29.       var _loc9_ = this._parent.player.z - this.z;
  30.       var _loc23_ = this._parent.player.z - this._parent.player.prevZ;
  31.       var _loc15_ = this._parent.player.x - this._parent.player.prevX;
  32.       var _loc4_ = Math.sqrt(Math.pow(_loc10_,2) + Math.pow(_loc9_,2));
  33.       var _loc19_ = _loc10_ * _loc15_ + _loc9_ * _loc23_;
  34.       var _loc5_ = this.walkDistance * 0.75;
  35.       if(_loc4_ < _loc5_ || _loc19_ < 0 || _loc4_ > this.walkDistance)
  36.       {
  37.          _loc23_ = this._parent.player.z - this._parent.player.prevZ;
  38.          var _loc25_ = this._parent.player.facingDirection * 25;
  39.          var _loc18_ = this._parent.player.x + _loc15_ * _loc7_ - _loc25_;
  40.          var _loc17_ = this._parent.player.z + _loc23_ * _loc7_;
  41.          var _loc20_ = _loc18_ - this.x;
  42.          var _loc21_ = _loc17_ - this.z;
  43.          var _loc11_ = Math.atan2(_loc21_,_loc20_);
  44.          var _loc24_ = Math.floor(_loc18_ - this.walkDistance * Math.cos(_loc11_));
  45.          var _loc22_ = Math.floor(_loc17_ - this.walkDistance * Math.sin(_loc11_));
  46.          var _loc16_ = _loc24_ - this.x;
  47.          var _loc14_ = _loc22_ - this.z;
  48.          var _loc8_ = Math.sqrt(Math.pow(_loc16_,2) + Math.pow(_loc14_,2));
  49.          var _loc3_ = _loc8_ / (_loc7_ + 1);
  50.          var _loc6_ = _loc16_ / _loc8_;
  51.          var _loc13_ = _loc14_ / _loc8_;
  52.          if(_loc4_ < _loc5_)
  53.          {
  54.             var _loc12_ = (_loc5_ - _loc4_) * 0.75 / _loc5_;
  55.             _loc6_ -= _loc10_ * _loc12_;
  56.             _loc13_ -= _loc9_ * _loc12_;
  57.          }
  58.          if(_loc3_ > this.maxSpeed)
  59.          {
  60.             _loc3_ = this.maxSpeed;
  61.          }
  62.          if(_loc4_ > this.maxDistance)
  63.          {
  64.             this._parent.player.stopRunning();
  65.          }
  66.          if(_loc3_ > 1.5)
  67.          {
  68.             this.x += _loc6_ * _loc3_;
  69.             this.z += _loc13_ * _loc3_;
  70.             this.setState("walk");
  71.             if(_loc3_ > 2)
  72.             {
  73.                if(_loc6_ < 0)
  74.                {
  75.                   this.facingDirection = -1;
  76.                   this.face("left");
  77.                }
  78.                if(_loc6_ > 0)
  79.                {
  80.                   this.facingDirection = 1;
  81.                   this.face("right");
  82.                }
  83.             }
  84.          }
  85.          else
  86.          {
  87.             this.faceDog();
  88.             this.setState("stand");
  89.          }
  90.       }
  91.       else
  92.       {
  93.          this.faceDog();
  94.          this.setState("stand");
  95.       }
  96.       super.onEnterFrame();
  97.       this.drawLead();
  98.    }
  99.    function drawLead()
  100.    {
  101.       var _loc7_ = this._parent.player.x - this.x;
  102.       var _loc9_ = this._parent.player.z - this.z;
  103.       var _loc8_ = Math.sqrt(Math.pow(_loc7_,2) + Math.pow(_loc9_,2));
  104.       this.graphics.arm._rotation = (- Math.abs(_loc7_)) / 2;
  105.       var _loc2_ = {x:this.graphics.arm.leadTop._x,y:this.graphics.arm.leadTop._y};
  106.       this.graphics.arm.localToGlobal(_loc2_);
  107.       this.graphics.globalToLocal(_loc2_);
  108.       this.graphics.leadBack._x = _loc2_.x;
  109.       this.graphics.leadBack._y = _loc2_.y;
  110.       this.graphics.leadFront._x = _loc2_.x;
  111.       this.graphics.leadFront._y = _loc2_.y;
  112.       var _loc5_ = {x:this._parent.player.graphics.leadBottom._x,y:this._parent.player.graphics.leadBottom._y};
  113.       this._parent.player.graphics.localToGlobal(_loc5_);
  114.       this.graphics.globalToLocal(_loc5_);
  115.       var _loc4_ = _loc5_.x - _loc2_.x;
  116.       var _loc3_ = _loc5_.y - _loc2_.y;
  117.       var _loc6_ = 30 * this.maxDistance / _loc8_;
  118.       if(_loc6_ > 40)
  119.       {
  120.          _loc6_ = 40;
  121.       }
  122.       this.graphics.leadFront.clear();
  123.       this.graphics.leadBack.clear();
  124.       if(this._parent.player.z < this.z)
  125.       {
  126.          this.graphics.leadFront.lineStyle(2,Heroes.Tools.getPlayerCollarColour(),100);
  127.          this.graphics.leadFront.moveTo(0,0);
  128.          this.graphics.leadFront.curveTo(_loc4_ / 2,_loc3_ / 2 + _loc6_,_loc4_,_loc3_);
  129.       }
  130.       else
  131.       {
  132.          this.graphics.leadBack.lineStyle(2,Heroes.Tools.getPlayerCollarColour(),100);
  133.          this.graphics.leadBack.moveTo(0,0);
  134.          this.graphics.leadBack.curveTo(_loc4_ / 2,_loc3_ / 2 + _loc6_,_loc4_,_loc3_);
  135.       }
  136.    }
  137.    function faceDog()
  138.    {
  139.       if(this._parent.player.x < this.x)
  140.       {
  141.          this.facingDirection = -1;
  142.          this.face("left");
  143.       }
  144.       else
  145.       {
  146.          this.facingDirection = 1;
  147.          this.face("right");
  148.       }
  149.    }
  150.    function setState(newState)
  151.    {
  152.       if(this.state != newState && this.state != "levelComplete")
  153.       {
  154.          this.state = newState;
  155.          this.graphics.gotoAndPlay(newState);
  156.       }
  157.    }
  158.    function face(newDirection)
  159.    {
  160.       if(newDirection != this.facing)
  161.       {
  162.          if(newDirection == "left")
  163.          {
  164.             this.facingDirection = -1;
  165.          }
  166.          else
  167.          {
  168.             this.facingDirection = 1;
  169.          }
  170.          this.facing = newDirection;
  171.          ┬º┬ºpush(this.gotoAndStop(newDirection));
  172.       }
  173.    }
  174.    function playSound(soundName)
  175.    {
  176.       if(soundName == "step1" || soundName == "step2" || soundName == "goodboy" || soundName == "letsgo" || soundName == "walkies")
  177.       {
  178.          super.playSound(soundName);
  179.       }
  180.       else if(getTimer() - this.speechTimer > 2500)
  181.       {
  182.          this.speechTimer = getTimer();
  183.          pi.AudioLibrary.stopSound("walkies");
  184.          pi.AudioLibrary.stopSound("comeontimesticking");
  185.          pi.AudioLibrary.stopSound("goodboy");
  186.          pi.AudioLibrary.stopSound("letsgo");
  187.          pi.AudioLibrary.stopSound("steady");
  188.          pi.AudioLibrary.stopSound("new_moveit");
  189.          pi.AudioLibrary.stopSound("new_easymate");
  190.          pi.AudioLibrary.stopSound("new_waitforme");
  191.          pi.AudioLibrary.stopSound("steady");
  192.          pi.AudioLibrary.stopSound("hupup");
  193.          pi.AudioLibrary.stopSound("sit");
  194.          if(soundName == "new_easymate" || soundName == "new_easythere" || soundName == "new_waitforme" || soundName == "steady")
  195.          {
  196.             this.slowSoundCount = this.slowSoundCount + 1;
  197.          }
  198.          if(soundName == "new_moveit" || soundName == "hupup")
  199.          {
  200.             trace("soundName=" + soundName);
  201.             this.fastSoundCount = this.fastSoundCount + 1;
  202.          }
  203.          super.playSound(soundName);
  204.       }
  205.    }
  206.    function playFasterSound()
  207.    {
  208.       switch(this.fastSoundCount % 2)
  209.       {
  210.          case 0:
  211.             this.playSound("hupup");
  212.             break;
  213.          case 1:
  214.             this.playSound("new_moveit");
  215.       }
  216.    }
  217.    function playSlowerSound()
  218.    {
  219.       switch(this.slowSoundCount % 3)
  220.       {
  221.          case 0:
  222.             this.playSound("steady");
  223.             break;
  224.          case 1:
  225.             this.playSound("new_easymate");
  226.             break;
  227.          case 2:
  228.             this.playSound("new_waitforme");
  229.       }
  230.    }
  231. }
  232.